import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreNoticeService extends BaseService<any> {
  private readonly logger = new Logger(CoreNoticeService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getList
   * 对应 PHP: CoreNoticeService_core::getList()
   * 逻辑类型: undefined - undefined
   */
  async getList(site_id: any[], keys: any[]) {
    // 基于PHP真实逻辑: getList
    // PHP原文: $list = $this->model->where([ [ 'site_id', '=', $site_id ] ])->select()->toArray();         if (!empty($list)) {             $list_key = array_column(...
const list = this.model.where([ [ 'site_id', '=', site_id ) )).select().toArray(];
        if (!!list)) {
            const list_key = array_column(list, 'key'];
            const list = array_combine(list_key, list);
  }

  /**
   * getAddonList
   * 对应 PHP: CoreNoticeService_core::getAddonList()
   * 逻辑类型: undefined - undefined
   */
  async getAddonList(site_id: any[], keys: any[]) {
    // 基于PHP真实逻辑: getAddonList
    // PHP原文: $list = $this->model->where([ [ 'site_id', '=', $site_id ] ])->select()->toArray();         if (!empty($list)) {             $list_key = array_column(...
const list = this.model.where([ [ 'site_id', '=', site_id ) )).select().toArray(];
        if (!!list)) {
            const list_key = array_column(list, 'key'];
            const list = array_combine(list_key, list);
  }

  /**
   * getInfo
   * 对应 PHP: CoreNoticeService_core::getInfo()
   * 逻辑类型: undefined - undefined
   */
  async getInfo(site_id: number, key: number) {
    // 基于PHP真实逻辑: getInfo
    // PHP原文: if (!array_key_exists($key, NoticeDict::getNotice())) throw new NoticeException('NOTICE_TYPE_NOT_EXIST');         $info = $this->model->where([ [ 'sit...
if (!array_key_exists(key, NoticeDict.getNotice())) throw new NoticeBusinessException('NOTICE_TYPE_NOT_EXIST'];
        const info = this.model.where([ [ 'site_id', '=', site_id ], [ 'key', '=', key ) )).findOrEmpty().toArray(];
        if (!!info)) {
            const notice = Object.assign(NoticeDict.getNotice(key), info];
  }

  /**
   * findRecord (原方法名: find)
   * 对应 PHP: CoreNoticeService_core::find()
   * 逻辑类型: undefined - undefined
   * 注意: 为避免与BaseService方法冲突，已重命名
   */
  async findRecord(site_id: number, key: number) {
    // 基于PHP真实逻辑: find
    // PHP原文: return $this->model->where([ [ 'site_id', '=', $site_id ], [ 'key', '=', $key ] ])->findOrEmpty();     }      /**      * 消息公共编辑      * @param int $sit...
return this.model.where([ [ 'site_id', '=', site_id ], [ 'key', '=', key ) )).findOrEmpty(];
    }

    /**
     * 消息公共编辑
     * @param int site_id
     * @param string key
     * @param data
     * @return bool
     */
    async edit(int site_id, string key, data)
    {
        const notice = this.find(site_id, key);
        if (notice.isEmpty()) {
            const notice_template = NoticeDict.getNotice(key];
            const wechat = notice_template[ 'wechat' ] || [];
            this.model.create(Object.assign([
                site_id: site_id,
                key: key,
                sms_content: notice_template[ 'sms']['content' ] || '',
                wechat_first: data[ 'wechat_first' ) || ( wechat[ 'first' ) || '' ),
                wechat_remark: data[ 'wechat_remark' ] || ( wechat[ 'remark' ) || '' ),
            ], data)];
  }

  /**
   * edit
   * 对应 PHP: CoreNoticeService_core::edit()
   * 逻辑类型: undefined - undefined
   */
  async edit(site_id: any[], key: any[], data: any[]) {
    // 基于PHP真实逻辑: edit
    // PHP原文: $notice = $this->find($site_id, $key);         if ($notice->isEmpty()) {             $notice_template = NoticeDict::getNotice($key);             $wech...
const notice = this.find(site_id, key);
        if (notice.isEmpty()) {
            const notice_template = NoticeDict.getNotice(key];
            const wechat = notice_template[ 'wechat' ] || [];
            this.model.create(Object.assign([
                site_id: site_id,
                key: key,
                sms_content: notice_template[ 'sms']['content' ] || '',
                wechat_first: data[ 'wechat_first' ) || ( wechat[ 'first' ) || '' ),
                wechat_remark: data[ 'wechat_remark' ] || ( wechat[ 'remark' ) || '' ),
            ], data)];
  }
}
